package com.example.demo.controller;

import com.example.demo.bean.BreedChicken;
import com.example.demo.bean.Inventory;
import com.example.demo.service.InventoryNumber;
import com.example.demo.service.SpreadSheet;
import org.apache.hc.core5.http.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

//查询总存栏跟各个栋舍的存栏
@Controller
public class InventoryController {

    @Autowired
    InventoryNumber inventoryNumber;

    @Autowired
    SpreadSheet spreadSheet;

    @GetMapping("/getInventoryNumb")
    public String getInventoryNumb(Model model, @RequestParam String date,@RequestParam String name) throws URISyntaxException, IOException, ParseException {
        List<Inventory> inventories = inventoryNumber.chickenInventory(date,name);
        model.addAttribute("inventoryNumbers", inventories);
        model.addAttribute("date", date);
        return "inventory/inventory";
    }

    @GetMapping("/getInventoryNumb1")
//    @ResponseBody
    public String getInventoryNumb1(Model model, @RequestParam String date,@RequestParam String name) throws URISyntaxException, IOException, ParseException {
        List<BreedChicken> inventories = inventoryNumber.BreedChickenNumber(date,name);
        model.addAttribute("inventoryNumbers", inventories);
        model.addAttribute("date", date);
//        return inventories;
        return "breed/breedChicken";
    }

    @GetMapping("/getInventoryDieNum")
//    @ResponseBody
    public String getInventoryDieNum(Model model,@RequestParam String date,@RequestParam String name,@RequestParam(required = false) String isAudit,@RequestParam(required = false) String isSend) throws URISyntaxException, IOException, ParseException {
        List inventories = spreadSheet.CommodityChickenDead(date, name, isAudit, isSend);
        model.addAttribute("inventoryDie", inventories);
        model.addAttribute("date", date);
        return "inventory/inventoryDie";
    }

}
